package com.jt.tenant.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Message;
import android.os.Handler;
import android.util.Log;
import android.widget.LinearLayout;

import com.amap.api.location.AMapLocation;
import com.jt.tenant.R;
import com.jt.tenant.action.LocationModular;
import com.jt.tenant.app.JTApplication;

import java.util.Calendar;

import qiu.niorgai.StatusBarCompat;

public class WelcomeActivity extends JTActivity {

    private SharedPreferences preferences;

    private LinearLayout welcome;

    private Calendar calendar = Calendar.getInstance();

    private Integer month,day;

    private LocationModular.OnLocateionChangeCallBack onLocateionChangeCallBack = new LocationModular.OnLocateionChangeCallBack() {

        @Override
        public void onLocation(AMapLocation aMapLocation) {

            JTApplication.lon = aMapLocation.getLongitude() + "";

            JTApplication.lat = aMapLocation.getLatitude() + "";

            Log.e("WELCOME-------",JTApplication.lon+"---------"+JTApplication.lat);

        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_welcome);



        JTApplication.locationModular.addOnLocateionChangeCallBack(onLocateionChangeCallBack);

        welcome = (LinearLayout) findViewById(R.id.lin_welcome);

        calendar = Calendar.getInstance();

        month = calendar.get(Calendar.MONTH)+1;

        day = calendar.get(Calendar.DAY_OF_MONTH);


        if(month == 12&&24 <= day&&day <= 26){




        }else if ((month == 12 && day == 31)||(month == 1 && 1 <= day && day <= 3)){




        }else if ((month == 1 && 27 <= day && day <= 31)||(month == 2 && 1 <= day && day <= 3)){



        }

        preferences = getSharedPreferences("tenant", MODE_PRIVATE);

        new Handler() {

            @Override
            public void handleMessage(Message msg) {

                //判断是否自动登录
                if (preferences.getString("AutoLogin", "").equals("yes")) {

                    startVerifyActivity(JTApplication.jtPreferences.readIsGuide() ?
                            (JTApplication.jtPreferences.readHaveUid() ? MainActivity.class: LoginActivity.class) : GuideActivity.class);

                    finish();
                } else {

                    if(JTApplication.jtPreferences.readIsGuide()==false){

                        startActivity(new Intent(context,GuideActivity.class));

                    }else{

                        startActivity(new Intent(context, LoginActivity.class));

                    }

                    finish();

                }

            }

        }.sendEmptyMessageDelayed(0, 3000);

    }

    @Override
    protected void onStop() {

        super.onStop();

        JTApplication.locationModular.removeOnLocateionChangeCallBack(onLocateionChangeCallBack);

    }

}
